package com.ky.pro.java.dt.common.web;

import lombok.Data;

@Data
public class ResultBean<T>  {

    private String resultCode;

    private String resultDes;

    private T data;

    public ResultBean(){

    }

    public ResultBean(String resultCode, String resultDes, T data) {
        this.resultCode = resultCode;
        this.resultDes = resultDes;
        this.data = data;
    }

    public ResultBean(String resultCode, String resultDes) {
        this.resultCode = resultCode;
        this.resultDes = resultDes;
    }

    public static final String RESP_CODE_FAIL = "0";
    public static final String RESP_CODE_SUCCESS = "1";

    public boolean isSuccess() {
        return RESP_CODE_SUCCESS.equals(resultCode);
    }

    public static ResultBean genError(String errMsg) {
        return new ResultBean(RESP_CODE_FAIL, errMsg);
    }

    public static <T> ResultBean genResult(T data) {
        return new ResultBean(RESP_CODE_SUCCESS, "OK", data);
    }

    public static ResultBean genResult(String errCode, String errMsg) {
        return new ResultBean(errCode, errMsg);
    }

    public static ResultBean genResult(String errCode, Throwable e) {
        return genResult(errCode, e.getMessage());
    }
}
